import java.util.ArrayList;
import java.util.List;

// 订单：关联顾客和点的菜品
public class Order {
    private Customer customer;       // 下单的顾客
    private List<Dish> orderedDishes; // 点的菜品列表
    private double totalPrice;       // 总价

    // 构造方法：创建订单时需要关联顾客
    public Order(Customer customer) {
        this.customer = customer;
        this.orderedDishes = new ArrayList<>(); // 初始化列表
        this.totalPrice = 0;
    }

    // 点餐方法：添加菜品（返回是否成功）
    public String addDish(Dish dish, int num) {
        if (num <= 0) {
            return "错误：点餐数量必须大于0";
        }
        // 调用菜品的减少库存方法
        boolean success = dish.reduceStock(num);
        if (success) {
            // 库存足够，添加到订单并计算总价
            for (int i = 0; i < num; i++) {
                orderedDishes.add(dish);
                totalPrice += dish.price;
            }
            return "成功添加：" + dish.name + " x" + num;
        } else {
            return "失败：" + dish.name + "库存不足";
        }
    }

    // 打印订单详情
    public void printOrder() {
        System.out.println("===== 订单详情 =====");
        System.out.println(customer.getInfo());
        System.out.println("--- 点的菜品 ---");
        for (Dish dish : orderedDishes) {
            System.out.println("- " + dish.name); // 只显示菜名
        }
        System.out.println("--- 总价：" + totalPrice + "元 ---");
    }
}